#pragma once
#include "commander/px4_custom_mode.h"
#include <px4_platform_common/module.h>
#include <px4_platform_common/module_params.h>
#include <uORB/Subscription.hpp>
#include <uORB/Publication.hpp>
#include <uORB/SubscriptionInterval.hpp>
#include <uORB/topics/parameter_update.h>
#include <uORB/topics/vehicle_local_position.h>
#include <uORB/topics/vehicle_local_position_setpoint.h>
#include <uORB/topics/vehicle_status.h>
#include <uORB/topics/home_position.h>
#include <uORB/topics/vehicle_command.h>
#include <uORB/topics/offboard_control_mode.h>
#include <uORB/topics/position_setpoint_triplet.h>
#include <uORB/topics/vehicle_command_ack.h>
#include <uORB/topics/vehicle_attitude_setpoint.h>
#include <uORB/topics/test_mavlink_rx.h>
#include <uORB/topics/follow_target.h>
#include <geo/geo.h>
#include <systemlib/mavlink_log.h>
#include <uORB/topics/mavlink_log.h>
#include <uORB/topics/a02_dist_to_target.h>
#include <uORB/topics/a03_buoy_sate.h>
#include <uORB/topics/distance_sensor.h>
#include <uORB/topics/a04_check.h>
#include <uORB/topics/a05_gcscheck.h>
#include <uORB/topics/transponder_report.h>
#include <uORB/topics/telemetry_status.h>
#include <uORB/SubscriptionMultiArray.hpp>
using namespace time_literals;

extern "C" __EXPORT int check_node_main(int argc, char *argv[]);


class CheckNode : public ModuleBase<CheckNode>, public ModuleParams
{
public:
	CheckNode(int example_param, bool example_flag);

	virtual ~CheckNode() = default;

	/** @see ModuleBase */
	static int task_spawn(int argc, char *argv[]);

	/** @see ModuleBase */
	static CheckNode *instantiate(int argc, char *argv[]);

	/** @see ModuleBase */
	static int custom_command(int argc, char *argv[]);

	/** @see ModuleBase */
	static int print_usage(const char *reason = nullptr);

	/** @see ModuleBase::run() */
	void run() override;

	/** @see ModuleBase::print_status() */
	int print_status() override;

private:

	/**
	 * Check for parameter changes and update them if needed.
	 * @param parameter_update_sub uorb subscription to parameter_update
	 * @param force for a parameter update
	 */
	void parameters_update(bool force = false);
float fly_alt=0;
void generateRandomNumber();
	DEFINE_PARAMETERS(
		(ParamInt<px4::params::SYS_AUTOSTART>) _param_sys_autostart,   /**< example parameter */
		(ParamInt<px4::params::SYS_AUTOCONFIG>) _param_sys_autoconfig,  /**< another parameter */
		(ParamFloat<px4::params::MIS_TAKEOFF_ALT>) _param_mis_takeoff_alt
	)

    uint64_t time_tick=hrt_absolute_time();
     uint64_t time_tick_gcs=hrt_absolute_time();
    int flag2=0;
    int rand,randgcs;
    vehicle_local_position_s _vehicle_local_position;
    vehicle_status_s _status;
    vehicle_command_s _command = {};
    offboard_control_mode_s ocm{};
    position_setpoint_triplet_s _pos_sp_triplet{};
    vehicle_command_ack_s _ack{};
    vehicle_local_position_setpoint_s sp_local{};
    vehicle_attitude_setpoint_s attitude_setpoint{};
    follow_target_s _target;
    test_mavlink_rx_s _test_mavlink_rx;
    double dist_to_target;
    a02_dist_to_target_s _a02_dist_to_target;
    a03_buoy_sate_s _a03_buoy_sate;
    distance_sensor_s _distance_sensor;
    a04_check_s _a04_check;
    a05_gcscheck_s _a05_gcscheck;
    bool check_gcspass=false;
    transponder_report_s _transponder_report;
int check_process(int n);
	// orb_advert_t *mavlink_log_pub{};
	// mavlink_log_pub = orb_advertise(ORB_ID(mavlink_log), &log_message);
orb_advert_t _mavlink_log_pub{nullptr};
    MapProjection _global_local_proj_ref{};
	// Subscriptions
	uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
        uORB::Subscription _vehicle_local_position_sub{ORB_ID(vehicle_local_position)};
        uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)};
       uORB::Subscription _test_mavlink_rx_sub{ORB_ID(test_mavlink_rx)};
        uORB::Subscription _follow_target_sub{ORB_ID(follow_target)};
	uORB::Subscription _distance_sensor_sub{ORB_ID(distance_sensor)};
	uORB::Subscription _a04_check_sub{ORB_ID(a04_check)};
    uORB::Subscription _a05_gcscheck_sub{ORB_ID(a05_gcscheck)};
    uORB::SubscriptionMultiArray<telemetry_status_s>        _telemetry_status_subs{ORB_ID::telemetry_status};
       // Publications
       uORB::Publication<offboard_control_mode_s>		_offboard_control_mode_pub{ORB_ID(offboard_control_mode)};
       uORB::Publication<vehicle_command_s>		_vehicle_command_pub{ORB_ID(vehicle_command)};
       uORB::Publication<position_setpoint_triplet_s>		_position_setpoint_triplet_pub{ORB_ID(position_setpoint_triplet)};
       uORB::Publication<vehicle_local_position_setpoint_s>	_trajectory_setpoint_pub{ORB_ID(trajectory_setpoint)};
       uORB::Publication<a02_dist_to_target_s>	_a02_dist_to_target_pub{ORB_ID(a02_dist_to_target)};
       uORB::Publication<a03_buoy_sate_s>	_a03_buoy_sate_pub{ORB_ID(a03_buoy_sate)};
       uORB::Publication<a04_check_s>	_a04_check_pub{ORB_ID(a04_check)};
       uORB::Publication<a05_gcscheck_s>	_a05_gcscheck_pub{ORB_ID(a05_gcscheck)};
       uORB::Publication<transponder_report_s>  _transponder_report_pub{ORB_ID(transponder_report)};
};

